class Attachment < ActiveRecord::Base
  mount_uploader :file, AttachmentUploader

  before_save :set_attachment_attributes

  protected

  def set_attachment_attributes
    if file.present? && file_changed?
      self.content_type = file.file.content_type
      self.file_size = file.file.size
      self.file_name = file.file.original_filename
    end
  end
end
